import {commonParams} from './config'
import axios from 'axios'

// 只获取vkey不能播放歌曲去，还需要cookie
// [2019/07/25] cookie携带字段：cookie:{key:'qqmusic_fromtag',value:66}
export function getVKey(mid, filename) {
  const url = '/api/proxy'
  const remoteUrl = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg'
  const data = Object.assign({}, commonParams, {
    loginUin: 0,
    hostUin: 0,
    format: 'json',
    platform: 'yqq',
    needNewCode: 0,
    cid: 205361747,
    uin: 0,
    songmid: mid,
    filename: filename,
    guid: '8773688539',
    url: remoteUrl
  })
  return axios.get(url, {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}

export function getLyric(mid) {
  const url = '/api/proxy'
  const remoteUrl = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'
  const data = Object.assign({}, commonParams, {
    '-': 'MusicJsonCallback_lrc',
    pcachetime: +new Date(),
    songmid: mid,
    loginUin: 0,
    hostUin: 0,
    platform: 'yqq.json',
    needNewCode: 0,
    format: 'json',
    url: remoteUrl
  })
  return axios.get(url, {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}
